<template>
<div class="tasks">
  <v-nav :path="path" :title="title"></v-nav>
  <div style="height:50px"></div>
  <div type="tab" class-name="tasks-tabs">
    <!-- <v-tab name="all-tasks" title="所有任务" status="active" -->
    <!-- distance="55" v-pull-to-refresh="refreshAll"> -->
      <!-- <v-layer></v-layer> -->
    <div class="content club" >
       <div id = "list" v-for="apply in applyList" @click="audit(apply.id)" >
        <div class="card">
            
            <div class="card-content">
                <div class="card-content-inner">
                  
                    <ul>
                        <li>俱乐部名称: {{apply.club_name}}</li>
                        <li>申请人: {{apply.name}}</li>
                     
                        <li v-if="apply.status==0">申请状态: 待审核</li>
                        <li v-if="apply.status==1">申请状态: 审核通过</li>
                        <li v-if="apply.status==2">申请状态: 审核拒绝</li>
                        <li>申请时间: {{apply.apply_time}} </li>
                        <!-- <li>俱乐部消耗房卡: {{order.name}}</li> -->
                        <!-- <li>俱乐部创建时间: {{club.crate_time}}</li> -->
                    </ul>
                    
                </div>
            </div>
        </div>
       </div>
    </div>
</template>

<script>
import $ from 'zepto'
import VNav from '../../components/Nav'
import _global from '../global'

export default {
  route: {
    data ({from, next}) { 
      if (from.path === '/user') {
        this.path = from.path
      }
    }
  },
  ready () {



  if (window.localStorage.getItem('user_id')) {
      self.userId = parseInt(window.localStorage.getItem('user_id'), 0)
    }
    $.init()
    this.getApplyList()
  },
  data () {
    return {
      path: '/user/club',
      title: '俱乐部申请审核管理',
      id: 0,
      applyList: [],
      predisabled: '',
      active: 'active',
      nextdisabled: '',
      userId: 0
    }
  },
  computed: {
    length () {
      return this.tasks.length
    }
  },
  methods: {
   

   //选择进行审核
    audit(apply_id){
        let self = this; 
                    var buttons1 = [
                      {
                        text: '是否允许加入俱乐部',
                        label: true
                      },
                      {
                        text: '同意',
                        bold: true,
                        onClick: function() {
                         self.auditApply(apply_id,1);
                        }
                      },
                      {
                        text: '拒绝',
                        color: 'danger',
                        onClick: function() {
                          self.auditApply(apply_id,2);
                        }
                      }
                    ];
                    var buttons2 = [
                      {
                        text: '取消',
                        bg: 'danger'
                      }
                    ];
                    var groups = [buttons1, buttons2];
                    $.actions(groups);   
    },


  //审核结果
    auditApply(apply_id,status){
       

      let self = this
      if (window.localStorage.getItem('user_id')) {
        self.userId = parseInt(window.localStorage.getItem('user_id'), 0)
        self.id = parseInt(window.localStorage.getItem('id'), 0)
      }

      
        this.$http.get(_global.url + '/auditApply?id=' + self.id + '&apply_id='+apply_id+'&status='+status).then(function(res) {
        if (typeof res.data === 'string') {
          res.data = JSON.parse(res.data)
        }
        if (res.data.errcode === -999) {
          // this.$router.go('/')
          window.location.href = _global.url + '/wxlogin'
          return
        }
        //提示并重新加载数据
        $.toast("操作成功");
        self.getApplyList();
      }, function(res) {
        console.log(res)
      })

    },

    getApplyList () {
      let self = this
      if (window.localStorage.getItem('user_id')) {
        self.userId = parseInt(window.localStorage.getItem('user_id'), 0)
        self.id = parseInt(window.localStorage.getItem('id'), 0)
      }
      // if (self.userId === 0) {
      //   return
      // }
      self.club_id = this.$route.params.club_id
      self.p_id = parseInt(this.$route.params.p_id, 0) || 1
      this.$http.get(_global.url + '/getClubApplyList?id=' + self.id + '&club_id='+self.club_id).then(function(res) {
        if (typeof res.data === 'string') {
          res.data = JSON.parse(res.data)
        }
        if (res.data.errcode === -999) {
          // this.$router.go('/')
          window.location.href = _global.url + '/wxlogin'
          return
        }
        self.applyList = res.data.data
      
        console.log(self.applyList)
       
      }, function(res) {
        console.log(res)
      })
    },
    classActive (index) {
      if (index === this.p_id) {
        return 'active'
      }
      return ''
    }
  },
  create () {
    this.getApplyList()
  },
  components: {
    VNav
  }
}
</script>

<style>
.tasks {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.tasks-tabs .buttons-tab {
  z-index: 10;
  margin-top:2.2rem;
}

.club {
  margin-top: 2.0rem;

}

club li {
list-style-type:none;
}

li {
list-style-type:none;
}
</style>
